﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QuickORM.BLL;
using QuickORM.Entity;
using QuickORM.Common;
public partial class Manage_WebPages_UserInfo_RoleManager : System.Web.UI.Page
{
    public string Mode
    {
        get { return ViewState["mode"] == null ? "add" : ViewState["mode"].ToString(); }
        set { ViewState["mode"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Mode = Request.QueryString["action"];
            string id = Request.QueryString["id"] as string;
            if (!string.IsNullOrEmpty(id))
            {
                T_Role roleInfo = new T_Role();
                roleInfo = BLLFactory<T_RoleManager>.Instance.FindByID(id);
                BindPage(roleInfo);
                ViewState["ID"] = id;
            }
        }
    }
    #region 填充页面
    /// <summary>
    /// 将数据填充到页面显示
    /// </summary>
    /// <param name="info">实体类数据</param>
    protected void BindPage(T_Role info)
    {
        txtRoleName.Value = info.RoleName;
        txtRoleDescription.Value = info.RoleDescription;
      
    }
    #endregion
    #region 提交数据
    protected void btn_Click(object sender, EventArgs eventArgs)
    {
        string js = "alert('操作失败！');";
        if (string.IsNullOrEmpty(txtRoleName.Value.Trim()))
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('角色名称不能为空！');", true);
            return;
        }
        T_Role role = new T_Role();
        role.RoleName = Util.querySQL(txtRoleName.Value.Trim());
        role.RoleDescription = Util.querySQL(txtRoleDescription.Value.Trim());
        if (Mode == "add")
        {
            //新增
            if (BLLFactory<T_RoleManager>.Instance.Insert(role))
            {
                js = "window.opener.select();window.close();";
            }

        }
        else
        {
            //修改
            if (BLLFactory<T_RoleManager>.Instance.Update(role, ViewState["ID"].ToString()))
            {
                js = "window.opener.select();window.close();";
            }
        }
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", js, true);
    }
    #endregion
}